package com.example.clienteencript;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class DesencriptarTextoActivity extends Activity {

	EditText etTexto;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actitity_desencriptar);

		etTexto = (EditText)findViewById(R.id.editText1);

		Button btn=(Button)findViewById(R.id.button1);
		Button btnVolver=(Button)findViewById(R.id.botonVolver);
		
		Bundle bundle = getIntent().getExtras();
		final String token = bundle.getString("token");

		btnVolver.setOnClickListener(new OnClickListener(){
        	@Override
        	public void onClick(View v){
        		Intent t = new Intent(DesencriptarTextoActivity.this, MenuServiciosActivity.class);
        		t.putExtra("token", token);
				startActivity(t);
				finish();     
        	}
        });

		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				
				android.controller.EncriptController oAndroidController = new android.controller.EncriptController();
				String response = oAndroidController.desencriptar(etTexto.getText().toString(), token);

				if(response.equals("Token Invalido")){
					mensaje(response);
					Intent t= new Intent(DesencriptarTextoActivity.this, MainActivity.class);
					String TokenIsDead = null;
					t.putExtra("token", TokenIsDead);
					startActivity(t);
					finish();         
				} else {
					mensaje(response);
				}

			}});
	}
	 /**
     * Imprime mensaje por pantalla tipo alert
     * @param cadena
     */
	public void mensaje(String cadena){
		Toast.makeText(this, cadena, Toast.LENGTH_SHORT).show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.encriptar_texto, menu);
		return true;
	}

}
